package com.cms.recursoshumanos.component.dialog;

import com.example.frontendrecursoshumanos.R;
import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.object.Articulo;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.TextView;

public class CustomAddArticuloDialog extends Dialog 
{
	private Articulo elArticulo;
    private NumberPicker mSpinner;
    public interface AddDialogListener 
  	{
        public void ready(Articulo elArticulo, int cantidad_selec);
        public void cancelled();
    }

    private AddDialogListener mReadyListener;

    public CustomAddArticuloDialog(Context context,Articulo elArticulo,AddDialogListener readyListener) 
    {
        super(context);
        this.setTitle("Agregar al Carrito");
        this.elArticulo = elArticulo;
        mReadyListener = readyListener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.elementos_add_carrito);
        mSpinner = (NumberPicker) findViewById (R.id.npCantidad);
        mSpinner.setMaxValue(elArticulo.getCantidadDisponible());
        mSpinner.setMinValue(Constant.MIN_CANTIDAD_ARTICULO_ADD);
        
        TextView textViewElArticulo = (TextView) findViewById(R.id.tvNombreArticulo);
        
        textViewElArticulo.setText("Cantidad del Articulo: \""+ elArticulo.getNombreArticulo()+"\" desea agregar?");
        
        Button buttonOK = (Button) findViewById(R.id.dialogOK);
        Button buttonCancel = (Button) findViewById(R.id.dialogCancel);
        buttonOK.setOnClickListener(new android.view.View.OnClickListener()
        {
            public void onClick(View v) 
            {
                
                mReadyListener.ready(elArticulo,mSpinner.getValue());
                CustomAddArticuloDialog.this.dismiss();
            }
        });
        buttonCancel.setOnClickListener(new android.view.View.OnClickListener(){
            public void onClick(View v) 
            {
                mReadyListener.cancelled();
                CustomAddArticuloDialog.this.dismiss();
            }
        });
    }
}